package com.vvv.shortlink.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vvv.shortlink.common.convention.result.Result;
import com.vvv.shortlink.admin.remote.ShortLinkProjectClient;
import com.vvv.shortlink.admin.remote.dto.req.RecycleBinPageReqDTO;
import com.vvv.shortlink.admin.remote.dto.req.RecycleBinRecoverReqDTO;
import com.vvv.shortlink.admin.remote.dto.req.RecycleBinRemoveReqDTO;
import com.vvv.shortlink.admin.remote.dto.req.RecycleBinSaveReqDTO;
import com.vvv.shortlink.admin.remote.dto.resp.LinkPageRespDTO;
import com.vvv.shortlink.common.toolkit.UserContext;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author vvv
 * @date 2024/2/19 14 52
 * discription
 */
@RestController
@RequiredArgsConstructor
public class AdminRecycleBinController {

    private final ShortLinkProjectClient shortLinkProjectClient;

    /**
     * 将短链接移至回收站
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/save")
    public Result<Void> saveLinkToBin(@RequestBody RecycleBinSaveReqDTO requestParam) {
        requestParam.setUserId(UserContext.getUserId());
        return shortLinkProjectClient.saveLinkToBin(requestParam);
    }

    /**
     * 分页查询回收站中的短链接
     */
    @GetMapping("/api/short-link/admin/v1/recycle-bin/page")
    public Result<Page<LinkPageRespDTO>> pageShortLinkInBin(RecycleBinPageReqDTO requestParam) {
        requestParam.setUserId(UserContext.getUserId());
        return shortLinkProjectClient.pageShortLinkInBin(requestParam);
    }

    /**
     * 从回收站中恢复短链接
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/recover")
    public Result<Void> recoverShortLinkFromBin(@RequestBody RecycleBinRecoverReqDTO requestParam) {
        requestParam.setUserId(UserContext.getUserId());
        return shortLinkProjectClient.recoverShortLinkFromBin(requestParam);
    }

    /**
     * 从回收站中移除短链接
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/remove")
    public Result<Void> removeShortLinkFromBin(@RequestBody RecycleBinRemoveReqDTO requestParam) {
        requestParam.setUserId(UserContext.getUserId());
        return shortLinkProjectClient.removeShortLinkFromBin(requestParam);
    }
}
